package team.xstudio.bedwarstoolkit.mixins;

import net.minecraft.world.entity.player.Player;
import net.minecraft.world.inventory.PlayerEnderChestContainer;
import net.minecraft.world.level.block.EnderChestBlock;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Redirect;
import team.xstudio.bedwarstoolkit.ingame.BWGameEventHandlers;

/**
 * Created in 2025/6/11
 * Project: bedwarstoolkit
 *
 * @author <a href="https://github.com/Bread-Nicecat">Bread_NiceCat</a>
 * <p>
 *
 * <p>
 **/
@Mixin(EnderChestBlock.class)
public abstract class MixinEnderChestBlock {
    @Redirect(method = "use",
            at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/player/Player;getEnderChestInventory()Lnet/minecraft/world/inventory/PlayerEnderChestContainer;")
    )
    //当玩家起床战争中时，返回队伍的末影箱，否则返回玩家的末影箱
    private PlayerEnderChestContainer use(Player player) {
        return BWGameEventHandlers.INSTANCE.useOnEnderChest(player);
    }
}
